﻿Imports BUS
Imports DTO


Public Class MH_BangDiemCaNhan

    Dim dsHS As New List(Of HocSinhDTO)

    Private Sub MH_BangDiemCaNhan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Load danh sách lớp
        Dim lopBUS As New LopBUS
        Dim dsL As New List(Of LopDTO)
        dsL = lopBUS.LayDanhSach()
        cboLop.DataSource = dsL
        cboLop.DisplayMember = ("TenLop")
        cboLop.ValueMember = ("MaLop")

        lblTenHS.Text = "..."
        lblNgaySinh.Text = "..."
        lblGioiTinh.Text = "..."
    End Sub

    Private Sub btnLayDS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLayDS.Click
        'Load danh sách học sin phân loại theo lớp vào gridview dsHocSinh
        Dim hsBUS As New HocSinhBUS()
        dsHS = hsBUS.TimKiemTheoLop(cboLop.SelectedValue)
        dgvDanhSachHS.Rows.Clear()

        For i As Integer = 0 To dsHS.Count - 1
            dgvDanhSachHS.Rows.Add(i + 1, dsHS(i).HoTen, dsHS(i).GioiTinh, dsHS(i).NgaySinh)
        Next

        dgvDanhSachDiem.Rows.Clear()
        lblTenHS.Text = "..."
        lblNgaySinh.Text = "..."
        lblGioiTinh.Text = "..."
    End Sub

    Private Sub btnXemDiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXemDiem.Click
        'Lâý dòng hiện hành trên dgvDanhSachHS
        Dim index As Integer = -1
        If (dgvDanhSachHS.CurrentRow IsNot Nothing) Then
            index = dgvDanhSachHS.CurrentRow.Index
        End If

        'Dựa vào index, lấy ra điểm của học sinh có mã tương ứng
        If (index >= 0 And index < dsHS.Count) Then
            Dim maHocSinh As Integer = dsHS(index).MaHocSinh
            Dim strSQL As String = " SELECT MONHOC.TenMon, CHITIETDIEM.Diem15P, CHITIETDIEM.Diem1T, CHITIETDIEM.DiemHK, HOCKY.HocKy "
            strSQL = strSQL + " FROM HOCKY INNER JOIN (MONHOC INNER JOIN (DIEMMONHOC INNER JOIN CHITIETDIEM ON DIEMMONHOC.MaDiemMonHoc = CHITIETDIEM.MaDiemMonHoc) ON MONHOC.MaMon = DIEMMONHOC.MaMon) ON HOCKY.MaHocKy = DIEMMONHOC.MaHocKy "
            strSQL = strSQL + " WHERE CHITIETDIEM.MaHocSinh=" + maHocSinh.ToString()
            Dim tvcBUS As New ThuVienChungBUS()
            Dim bangDiem As New DataTable
            bangDiem = tvcBUS.LayBang(strSQL)

            'Load lên dgvDanhSachDiem
            dgvDanhSachDiem.Rows.Clear()
            For i As Integer = 0 To bangDiem.Rows.Count - 1
                dgvDanhSachDiem.Rows.Add(bangDiem.Rows(i)("TenMon"), bangDiem.Rows(i)("Diem15P"), bangDiem.Rows(i)("Diem1T"), bangDiem.Rows(i)("DiemHK"), bangDiem.Rows(i)("HocKy"))
            Next
            lblTenHS.Text = dsHS(index).HoTen
            lblNgaySinh.Text = dsHS(index).NgaySinh.ToShortDateString
            lblGioiTinh.Text = dsHS(index).GioiTinh
        End If
    End Sub


End Class